import React from 'react'
import PureRenderMixin from 'react-addons-pure-render-mixin'
import { Link,hashHistory } from 'react-router'

import SearchInput from '../SearchInput'

import './style.less';

class HomeHeader extends React.Component {
    constructor(props, context) {
        super(props, context);
        this.shouldComponentUpdate = PureRenderMixin.shouldComponentUpdate.bind(this);
        this.state={
            kwd:''
        }
    }
    render() {
        return (
            <div id="home-header" className="clear-fix">
                <div className="home-header-left float-left">
                    <Link to="/city">
                        <span>{this.props.cityName}</span>
                        &nbsp;
                        <i className="icon-angle-down"></i>
                    </Link>
                </div>
                <div className="home-header-right float-right">
                    <Link to="/login">
                        <i className="icon-user"></i>
                    </Link>
                </div>
                <div className="home-header-middle">
                    <div className="search-container">
                        <i className="icon-search"></i>
                        {/*<input placeholder="请输入关键字" type="text"*/}
                               {/*value={this.state.kwd}*/}
                               {/*onChange={this.ChangeHandle.bind(this)}*/}
                               {/*onKeyUp={this.KeyUpHandle.bind(this)}*/}
                        {/*/>*/}
                        &nbsp;
                        <SearchInput
                            value=""
                            enterHandle={this.enterHandle.bind(this)}
                        />
                    </div>
                </div>
            </div>
        )
    }

    enterHandle(value){
        hashHistory.push('/search/all/'+encodeURIComponent(value))
    }

    ChangeHandle(e){
        var val=e.target.value;
        this.setState({
            kwd:val
        })
    }
    KeyUpHandle(e){
        if(e.keyCode!==13){
            return
        }
        hashHistory.push('/search/all/'+encodeURIComponent(this.state.kwd))
    }
}

export default HomeHeader